export function greaterOrEqual<T>(items: T[], key: string, value: string | number): T[] {
  try {
    const val = isNaN(Number(value)) ? value : Number(value);
    const result = items.filter((item) => item[key] > val || item[key] == val);
    return result;
  } catch (error) {
    console.error(error);
    return [];
  }
}

export function lessThanOrequal<T>(items: T[], key: string, value: string) {
  try {
    const val = isNaN(Number(value)) ? value : Number(value);
    const result = items.filter((item) => item[key] < val || item[key] == val);
    return result;
  } catch (error) {
    console.error(error);
    return [];
  }
}

export function equalTo<T>(items: T[], key: string, value: string) {
  try {
    const result = items.filter((item) => item[key] == value);
    return result;
  } catch (error) {
    console.error(error);
    return [];
  }
}

export function include<T>(items: T[], key: string, value: string) {
  try {
    const result = items.filter((item) => {
      if (item[key] === null || item[key] === undefined) {
        return false;
      } else {
        return item[key].toString().match(value);
      }
    });
    return result;
  } catch (error) {
    console.error(error);
    return [];
  }
}

export function notInclude<T>(items: T[], key: string, value: string) {
  try {
    const result = items.filter((item) => {
      if (item[key] === null || item[key] === undefined) {
        return false;
      } else {
        return !item[key].toString().match(value);
      }
    });
    return result;
  } catch (error) {
    console.error(error);
    return [];
  }
}

export function isNull<T>(items: T[], key: string) {
  try {
    const result = items.filter((item) => !item[key]);
    return result;
  } catch (error) {
    console.error(error);
    return [];
  }
}

export function notNull<T>(items: T[], key: string) {
  try {
    const result = items.filter((item) => item[key]);
    return result;
  } catch (error) {
    console.error(error);
    return [];
  }
}
